package com.xszx.servlet.user.address;

import com.xszx.bean.Address;
import com.xszx.bean.Order;
import com.xszx.bean.dto.CartDto;
import com.xszx.dao.AddressDao;
import com.xszx.dao.UserDao;
import com.xszx.dao.impl.AddressDaoImpl;
import com.xszx.dao.impl.UserDaoImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/UpdateAddressFirstServlet")
public class UpdateAddressFirstServlet extends HttpServlet{
    static AddressDao addressDao = new AddressDaoImpl();
    static UserDao userDao = new UserDaoImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");

        String username = req.getSession().getAttribute("username").toString();
        if (!username.equals("tourist")) {
            Integer userId = userDao.getUserIdByUsername(username);
            int id = Integer.parseInt(req.getParameter("id"));
            addressDao.updateAddressFirst(id, userId);
            resp.sendRedirect("BuildOrderServlet");
        }


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}